<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="/js/jquery.min.js"></script>
</head>
<body>
<h2>哈尔滨信息工程学院 - 登录</h2>
<input type="text" id="username" placeholder="用户名">
<input type="password" id="password" placeholder="密码">
<button onclick="login()">登录</button>

<script>
    function login() {
        const name = $("#username").val().trim();
        const pass = $("#password").val().trim(); // 明文

        if (!name || !pass) {
            alert("请填写账号和密码");
            return;
        }

        $.post("/user/tologin", { name, pass }, function (res) {
            if (res == 1) {
                window.location.href = "/course/view";
            } else {
                alert("账号或密码错误");
            }
        });
    }

    // 回车登录
    $(document).keypress(function (e) {
        if (e.which == 13) login();
    });
</script>
</body>
</html>